package com.gopay.scheduler.job;

import java.util.Calendar;
import java.util.Date;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.common.constants.ep.EpBindState;
import com.gopay.common.util.DateUtils;
import com.gopay.remote.cps.expresspay.EpBankCardRemoteService;
import com.gopay.scheduler.GopayBaseJob;

/**
 * 移动支付，设备和手机绑定关系表数据清理JOB
 * @author HENRY.M
 *
 */
public class MobileDeviceBindRelCleanJob extends GopayBaseJob {
	
	private Logger logger = LoggerFactory.getLogger(MobileDeviceBindRelCleanJob.class);
	
	@Resource(name = "epBankCardService")
	private EpBankCardRemoteService epBankCardService;
	
	
	/**
	 * 默认清理七天以前的临时状态的绑定关系
	 */
	private static final int DATE_BEFORE = -7;
	
	@Override
	public void doJobInternal() {
		

		Date bindDateBefore = DateUtils.add(new Date(), Calendar.DATE, DATE_BEFORE);
		EpBindState state = EpBindState.TEMP;
		
		logger.info("开始清理快捷支付银行卡绑定关系表, 参数 bindDateBefore={}, state = {}", bindDateBefore, state);
		
		boolean res = epBankCardService.cleanBindInfoByBindTimeAndStatus(bindDateBefore, state);
		
		logger.info("结束清理快捷支付银行卡绑定关系表, 参数 bindDateBefore={}, state = {}， Result = {}", new Object[]{bindDateBefore, state, res});

		logger.info("开始清理快捷支付银行卡冻结状态, 参数 bindDateBefore={}, state = {}", bindDateBefore, state);
		
		boolean res1 = epBankCardService.clearBankCardStatus();
		
		logger.info("结束清理快捷支付银行卡冻结状态, 参数 bindDateBefore={}, state = {}， Result = {}", new Object[]{bindDateBefore, state, res1});
		
		
		
	}

}
